﻿using System;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ThingyCloudWPF.World
{
	public class Blob
	{
		public DateTime LastUpdate { get; private set; }

		/// <summary>
		/// Create a new blob
		/// </summary>
		/// <param name="id">The ID of the blob (from parlevision)</param>
		/// <param name="x">The X location where to create</param>
		/// <param name="y">The Y location where to create</param>
		/// <param name="width">The width of the bounding rect (from PV)</param>
		/// <param name="height">The height of the bounding rect (from PV)</param>
		public Blob(uint id, uint x, uint y, uint width, uint height)
		{
			LastUpdate = DateTime.Now;
			ID = id;
			X = x;
			Y = y;
			Width = width;
			Height = height;
		}

		/// <summary>
		/// Returns or privately sets the ID of this blob
		/// </summary>
		public uint ID
		{
			get;
			private set;
		}

		/// <summary>
		/// The X position of the blob. To change, use <code>Move(x,y)</code>
		/// </summary>
		public uint X
		{
			get;
			private set;
		}

		/// <summary>
		/// The Y position of the blob. To change, use <code>Move(x,y)</code>
		/// </summary>
		public uint Y
		{
			get;
			private set;
		}

		public uint Width
		{
			get;
			private set;
		}

		public uint Height
		{
			get;
			private set;
		}

		public uint Size
		{
			get
			{
				return Width * Height;
			}
		}

		public Rectangle BoundingRect
		{
			get
			{
				return new Rectangle((int)Math.Max(0, X-10), (int)Math.Max(0, Y-10), Math.Min(Globals.ScreenWidth, (int)Width+20), Math.Min(Globals.ScreenHeight, (int)Height+20));
			}
		}
		
		/// <summary>
		/// Moves a blob to a new position
		/// </summary>
		/// <param name="x"></param>
		/// <param name="y"></param>
		/// <param name="width"></param>
		/// <param name="height"></param>
		public void Move(uint x, uint y, uint width, uint height)
		{
			LastUpdate = DateTime.Now;

			X = x;
			Y = y;
			Width = width;
			Height = height;
		}
	}
}
